class Myhammer{
	constructor(obj,options){
		// alert(this)
		// this.a=123;
		this.eventQueue=[];
		this._start_time=0;
		this._timer=null;
		obj.addEventListener('touchstart',this._start.bind(this),false);
		obj.addEventListener('touchmove',this._move.bind(this),false);
		obj.addEventListener('touchend',this._end.bind(this),false);
	}
	on(name,fn){
		this.eventQueue.push({name,fn});
	}
	_start(){//记录时间
		// alert(this)
		this._start_time=Date.now();
		clearTimeout(this.timer);
		this._timer=setTimeout(function(){
			// console.log('触发press')
			this.eventQueue.forEach(item=>{
				if(item.name=='press'){
					item.fn();
				}
			});
			// this._trigger_event('press');
		}.bind(this),250)
	}
	_move(){

	}
	_end(){//记录时间
		if(Date.now()-this._start_time<250){
			// console.log('触发tap');
			this.eventQueue.forEach(item=>{
				if(item.name=='tap'){
					item.fn();
				}
			})
			// this._trigger_event('tap');
			clearTimeout(this._timer);
		}
	}
	_trigger_event(name){//封装。重用
		this.eventQueue.forEach(item=>{
			if(item.name==name){
				item.fn();
			}
		})
	}
}